package dao.Impl;

import dao.NewsDao;
import model.NewsModel;
import util.JDBC;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class NewsImpl implements NewsDao {

    @Override
    public List<NewsModel> getTitleList() {
        String sql="select * from `hs_news`";
        ResultSet r = JDBC.getResultSet(sql);
        List<NewsModel> list =new ArrayList<>();
        try {
            while (r.next()) {
                NewsModel model = new NewsModel();
                model.setHref(r.getString("href"));
                model.setTitle(r.getString("title"));
                list.add(model);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBC.close();
        }
        return list;
    }

    @Override
    public List<NewsModel> getContentList() {
        String sql="select * from `hs_newsContent`";
        ResultSet r = JDBC.getResultSet(sql);
        List<NewsModel> list =new ArrayList<>();
        try {
            while (r.next()) {
                NewsModel model = new NewsModel();
                model.setContent(r.getString("content"));
                model.setCreatTime(r.getString("time"));
                model.setNet(r.getString("net"));
                list.add(model);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            JDBC.close();
        }
        return list;
    }
}
